<template>
  <el-dropdown @command="handleThemeChange" trigger="click">
    <el-button circle>
      <el-icon :size="16" v-if="themeStore.currentTheme === 'light'">
        <Sunny />
      </el-icon>
      <el-icon :size="16" v-else>
        <Moon />
      </el-icon>
    </el-button>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item command="light" :disabled="themeStore.currentTheme === 'light'">
          <el-icon>
            <Sunny />
          </el-icon>
          <span>浅色模式</span>
        </el-dropdown-item>
        <el-dropdown-item command="dark" :disabled="themeStore.currentTheme === 'dark'">
          <el-icon>
            <Moon />
          </el-icon>
          <span>深色模式</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import { Sunny, Moon } from '@element-plus/icons-vue'
import { useTheme } from '../store/theme'

const themeStore = useTheme()

const handleThemeChange = (theme: string) => {
  themeStore.toggleTheme(theme as 'light' | 'dark')
}
</script>

<style scoped>
.el-button {
  border: none;
  background-color: transparent;
}
</style>